/*
 * TablesFrame.java
 *
 * Created on 28. leden 2009, 20:28
 */

package jmenu.gui;

import java.awt.Dimension;
import javax.swing.JTabbedPane;
import jmenu.dbmodels.MSectionsOfFood;
import jmenu.dbmodels.MSubsectionsOfFood;
import jmenu.main.Config;
import jmenu.main.Icons;

/**
 *
 * @author  Roman
 */
public class TablesFrame extends DefaultFrame {


    /** Creates new form TablesFrame */
    public TablesFrame()
    {
        initComponents();
        this.setSize(1000, 600);
        this.setResizable(false);
    }

    private void init()
    {
        new FoodPanelThread(tablesstatusPanel,this.sectionTabbedPane).start();
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sectionTabbedPane = new javax.swing.JTabbedPane();
        tablesstatusPanel = new jmenu.gui.StatusPanel();
        searchPanel = new jmenu.gui.SearchPanel();
        searchButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(850, 600));
        setName("Tables of Food"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        sectionTabbedPane.setAutoscrolls(true);
        sectionTabbedPane.setFocusable(false);
        sectionTabbedPane.setName("sectionTabbedPane"); // NOI18N

        tablesstatusPanel.setMinimumSize(new java.awt.Dimension(100, 20));
        tablesstatusPanel.setName("tablesstatusPanel"); // NOI18N

        searchPanel.setName("searchPanel"); // NOI18N

        searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/search-32.png"))); // NOI18N
        searchButton.setToolTipText("Hledat");
        searchButton.setMaximumSize(new java.awt.Dimension(40, 40));
        searchButton.setMinimumSize(new java.awt.Dimension(40, 40));
        searchButton.setName("searchButton"); // NOI18N
        searchButton.setPreferredSize(new java.awt.Dimension(40, 40));
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(569, Short.MAX_VALUE)
                .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(searchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(tablesstatusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 834, Short.MAX_VALUE)
            .addComponent(sectionTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 834, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(searchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sectionTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 499, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablesstatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-850)/2, (screenSize.height-613)/2, 850, 613);
    }// </editor-fold>//GEN-END:initComponents

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    init();
}//GEN-LAST:event_formWindowOpened

private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
    this.sectionTabbedPane.setComponentAt(0, new FoodPanel(Config.getKernel().queries.searchFoods(this.searchPanel.getSearchText())));
    this.sectionTabbedPane.setSelectedIndex(0);
}//GEN-LAST:event_searchButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton searchButton;
    private jmenu.gui.SearchPanel searchPanel;
    private javax.swing.JTabbedPane sectionTabbedPane;
    private jmenu.gui.StatusPanel tablesstatusPanel;
    // End of variables declaration//GEN-END:variables

}
